package com.bestcem.xm.componet.sms.aliyun;

import com.bestcem.xm.componet.sms.aliyun.core.AliyunSmsClient;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
@ConditionalOnClass(name = "com.aliyuncs.IAcsClient")
@EnableConfigurationProperties({AliyunSmsProperties.class})
public class AliyunSmsAutoConfiguration {

    private final AliyunSmsProperties aliyunSmsProperties;

    @ConditionalOnProperty(prefix = "sms", name = "smsType", havingValue = "aliyun")
    @Bean
    @ConditionalOnMissingBean
    public AliyunSmsClient smsClient() {
        return new AliyunSmsClient(aliyunSmsProperties);
    }
}
